﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace Eniux.Windows.ThreeDEngine.Visual3Ds
{
   public class BendedCuboidVisual3D:ExtrudedVisual3D
    {

        #region 注册属性

        #region Width

        /// <summary>
        /// 宽度属性
        /// </summary>
       public static readonly DependencyProperty WidthProperty = DependencyProperty.Register(
            "Width", typeof(double), typeof(BendedCuboidVisual3D), new UIPropertyMetadata(5.0, SizeChanged));

        /// <summary>
        /// 获取或设置宽度
        /// </summary>
        public double Width
        {
            get { return (double)GetValue(WidthProperty); }
            set { SetValue(WidthProperty, value); }
        }
        #endregion

        #region Height

        /// <summary>
        /// 高度属性.
        /// </summary>
        public static readonly DependencyProperty HeightProperty = DependencyProperty.Register(
            "Height", typeof(double), typeof(BendedCuboidVisual3D), new UIPropertyMetadata(0.1, SizeChanged));

        /// <summary>
        /// 获取或设置高度
        /// </summary>
        public double Height
        {
            get { return (double)GetValue(HeightProperty); }
            set { SetValue(HeightProperty, value); }
        }

        #endregion

        #endregion

        #region 构造、析构
        public BendedCuboidVisual3D()
        {

        } 
        #endregion


        #region 方法

        /// <summary>
        /// 
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        protected static void SizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((BendedCuboidVisual3D)d).UpdateSection();
        }

        /// <summary>
        /// 
        /// </summary>
        private void UpdateSection()
        {
            var pc = new PointCollection();
            for (int i = 0; i < 3;i++ )
            {
               pc.Add(new Point(Width / 3 * i,0));
            }
            pc.Add(new Point(Width, Height / 2));
            for (int i = 0; i < 3; i++)
            {
                pc.Add(new Point(Width / 3 * (2 - i), Height));
            }
            pc.Add(new Point(0, 0));
            this.Section = pc;
        }

        #endregion
    }
}
